package com.todo.member.infrastructure.convert;

import com.todo.common.utils.DateUtils;
import com.todo.common.utils.TodoCommonUtils;
import com.todo.member.common.enums.MemberLevelStatusEnum;
import com.todo.member.common.enums.MemberVipStatusEnum;
import com.todo.member.infrastructure.entity.domain.MemberInfoDO;
import com.todo.member.infrastructure.entity.po.MemberInfoPO;
import com.todo.member.infrastructure.entity.po.MemberLevelInfoPO;
import com.todo.member.infrastructure.entity.po.MemberMedalInfoPO;
import com.todo.member.infrastructure.entity.po.MemberVipInfoPO;

import java.util.Date;

/**
 * @author azhebuxing
 * @date 2025/2/11 12:24
 * @description
 */
public class MemberBaseConvert {
    public static MemberInfoPO buildInsertMemberInfo(Long userId) {
        MemberInfoPO memberInfoPO = new MemberInfoPO();
        memberInfoPO.setId(TodoCommonUtils.buildLongGuid());
        memberInfoPO.setUserId(userId);
        memberInfoPO.setLevel(TodoCommonUtils.DEFAULT_MEMBER_LEVEL_ONE_CODE);
        memberInfoPO.setVipCode(TodoCommonUtils.DEFAULT_MEMBER_VIP_ONE_CODE);
        memberInfoPO.setVipVersion(1);
        memberInfoPO.setVipExpiredTime(DateUtils.dateTime("2099-12-31", DateUtils.YYYY_MM_DD));
        memberInfoPO.setGrowthCount(0);
        memberInfoPO.setPointsCount(0);
        memberInfoPO.setBonusCount(0);
        memberInfoPO.setIsDelete(0);
        memberInfoPO.setCreateTime(new Date());
        memberInfoPO.setUpdateTime(new Date());
        return memberInfoPO;
    }

    public static MemberInfoDO buildMemberInfoDO(MemberInfoPO memberInfoPO, MemberMedalInfoPO memberMedalInfoPO, MemberVipInfoPO memberVipInfoPO) {
        if (memberInfoPO == null) {
            return null;
        }
        MemberInfoDO memberInfoDO = new MemberInfoDO();
        memberInfoDO.setId(memberInfoPO.getId());
        memberInfoDO.setUserId(memberInfoPO.getUserId());
        memberInfoDO.setBonusCount(memberInfoPO.getBonusCount());
        memberInfoDO.setPointsCount(memberInfoPO.getPointsCount());
        memberInfoDO.setGrowthCount(memberInfoPO.getGrowthCount());
        memberInfoDO.setLevel(memberInfoPO.getLevel());
        memberInfoDO.setVipInfoDO(convertMemberVipInfoDO(memberInfoPO, memberVipInfoPO));
        memberInfoDO.setMedalInfoDO(convertMemberMedalInfoDO(memberMedalInfoPO));
        memberInfoDO.setIsDelete(memberInfoPO.getIsDelete());
        memberInfoDO.setCreateTime(memberInfoPO.getCreateTime());
        memberInfoDO.setUpdateTime(memberInfoPO.getUpdateTime());
        return memberInfoDO;
    }

    private static MemberInfoDO.MedalInfoDO convertMemberMedalInfoDO(MemberMedalInfoPO memberMedalInfoPO) {
        if (memberMedalInfoPO == null) {
            return null;
        }
        MemberInfoDO.MedalInfoDO medalInfoDO = new MemberInfoDO.MedalInfoDO();
        medalInfoDO.setMedalCode(memberMedalInfoPO.getMedalCode());
        medalInfoDO.setTitle(memberMedalInfoPO.getTitle());
        medalInfoDO.setDesc(memberMedalInfoPO.getDesc());
        medalInfoDO.setMedalClassify(memberMedalInfoPO.getMedalClassify());
        medalInfoDO.setCarryDisplayImg(memberMedalInfoPO.getCarryDisplayImg());
        return medalInfoDO;

    }

    private static MemberInfoDO.VIPInfoDO convertMemberVipInfoDO(MemberInfoPO memberInfoPO, MemberVipInfoPO memberVipInfoPO) {
        if (memberVipInfoPO == null) {
            return null;
        }
        MemberInfoDO.VIPInfoDO vipInfoDO = new MemberInfoDO.VIPInfoDO();
        vipInfoDO.setName(memberVipInfoPO.getName());
        vipInfoDO.setVipCode(memberVipInfoPO.getVipCode());
        vipInfoDO.setVipVersion(memberVipInfoPO.getVipVerison());
        vipInfoDO.setDesc(memberVipInfoPO.getDesc());
        vipInfoDO.setVipType(memberVipInfoPO.getVipType());
        vipInfoDO.setVipExpiredTime(memberInfoPO.getVipExpiredTime());
        return vipInfoDO;
    }

    public static MemberLevelInfoPO buildUpdateMemberLevelInfo(MemberLevelInfoPO memberLevelInfoPO) {
        MemberLevelInfoPO operateData = new MemberLevelInfoPO();
        operateData.setId(TodoCommonUtils.buildLongGuid());
        operateData.setLevel(memberLevelInfoPO.getLevel());
        operateData.setLevelName(memberLevelInfoPO.getLevelName());
        operateData.setLevelCode(memberLevelInfoPO.getLevelCode());
        operateData.setDesc(memberLevelInfoPO.getDesc());
        operateData.setUpgradeRule(memberLevelInfoPO.getUpgradeRule());
        operateData.setLevelPrivilege(memberLevelInfoPO.getLevelPrivilege());
        operateData.setLevelReward(memberLevelInfoPO.getLevelReward());
        operateData.setVersion(memberLevelInfoPO.getVersion() + 1);
        //初始创建内容都为草稿状态
        operateData.setStatus(MemberLevelStatusEnum.DRAFT.getType());
        operateData.setIsDelete(memberLevelInfoPO.getIsDelete());
        operateData.setCreateTime(new Date());
        operateData.setUpdateTime(new Date());
        return operateData;
    }

    public static MemberVipInfoPO buildUpdateMemberVipInfoPO(MemberVipInfoPO memberVipInfoPO) {
        if (memberVipInfoPO == null) {
            return null;
        }
        MemberVipInfoPO operateData = new MemberVipInfoPO();
        operateData.setId(TodoCommonUtils.buildLongGuid());
        operateData.setName(memberVipInfoPO.getName());
        operateData.setVipCode(memberVipInfoPO.getVipCode());
        operateData.setDesc(memberVipInfoPO.getDesc());
        operateData.setVipType(memberVipInfoPO.getVipType());
        operateData.setMarkingPrice(memberVipInfoPO.getMarkingPrice());
        operateData.setSellPrice(memberVipInfoPO.getSellPrice());
        operateData.setEffectiveDuration(memberVipInfoPO.getEffectiveDuration());
        operateData.setPurchaseInstructions(memberVipInfoPO.getPurchaseInstructions());
        operateData.setAfterSalesDescription(memberVipInfoPO.getAfterSalesDescription());
        operateData.setEquityStatement(memberVipInfoPO.getEquityStatement());
        operateData.setVipPrivilege(memberVipInfoPO.getVipPrivilege());
        operateData.setStatus(MemberVipStatusEnum.DRAFT.getType());
        operateData.setVersion(memberVipInfoPO.getVersion() + 1);
        operateData.setIsDelete(0);
        operateData.setCreateTime(new Date());
        operateData.setUpdateTime(new Date());
        return operateData;
    }
}
